package algorithms;

import java.io.BufferedInputStream;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class JBIG2 implements LosslessCompressionAlgorithm {

	private String _extension = "jbig2";

	@Override
	public void encode(File fileIn, File fileOut) throws IOException {

		Process p = Runtime.getRuntime().exec("jbig2 -s " + fileIn.getAbsolutePath());
		BufferedInputStream bis = new BufferedInputStream(p.getInputStream());
		BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(fileOut));
		
		byte[] buffer = new byte[512];
		int byteRead = 0;
		while ((byteRead = bis.read(buffer)) != -1) {
			bos.write(buffer, 0, byteRead);
		}
		bis.close();
		bos.close();
	}

	@Override
	public void decode(File fileIn, File fileOut) throws IOException {

	}

	@Override
	public String getFileExtension() {
		return _extension;
	}

	@Override
	public void setFileExtension(String name) {
		_extension = name;
	}

}
